<?php
/**
 * Generic page to register a user
 */
?>
<?php
require_once '../dbms_university_courses_mvc/Model/model_require_once.php';
?>
<?php 
function getProfileRegistration($user_type_id) {
	?>
	
<script type="text/javascript">
var first_name, last_name, gender, date_of_birth, local_address, username, password;
var user_type_id = <?php echo $user_type_id; ?>;

function setGender(g){
	gender = g;
}

<?php
/* @var $profile Profile */
$profiles = Profile::getProfiles ();
$usernames = array ();
foreach ( $profiles as $profile ) {
	array_push ( $usernames, $profile->get_username () );
}

?>
var usernames = <?php
echo json_encode ( $usernames );
?>;

</script>



<input type="hidden" id="username" />
<input type="hidden" id="password" />

<table>
	<tr>
		<th>First Name:</th>
		<td><input
			onfocus="if(this.value == 'First Name'){
	this.value = '';
	}"
			onblur="first_name = this.value;" value='First Name'
		/></td>
	</tr>
	<tr>
		<th>Last Name:</th>
		<td><input
			onfocus="if(this.value == 'Last Name'){
	this.value = '';
	}"
			onblur="last_name = this.value;" value='Last Name'
		/></td>
	</tr>
	<tr>
		<th>Gender:</th>
		<td>
				<?php
				Gender::print_Gender_dropdown ( Gender::getGenders (), "gender", "", "setGender" );
				?>
			</td>
	</tr>
	<tr>
		<th>Date of Birth:</th>
		<td><input
			onfocus="if(this.value == 'Date of Birth'){
	this.value = '';
	}"
			onblur="date_of_birth = this.value;" value='Date of Birth'
		/> <em>Format: yyyy-mm-dd</em></td>
	</tr>
	<tr>
		<th>Address:</th>
		<td colspan="2"><input
			onfocus="if(this.value == 'Local Address'){
	this.value = '';
	}"
			onblur="local_address = this.value;" value='Local Address' size="45"
		/></td>
	</tr>

	<tr>
		<th>Username:</th>
		<td><input id='username_input'
			onfocus="if(this.value == 'Username'){
	this.value = '';
	}"
			onblur="
			if($.inArray(this.value, usernames) == -1){
				username = this.value;
				$('#username_warning').hide();	
			}
			else{		
				$('#username_warning').text('The username ' + this.value + ' is already taken, please choose another.');	
				$('#username_warning').fadeIn();		
				$('#username_input').focus();
			}		
			" value='Username'
		/><em><span id="username_warning" style="color:red; display:none;"></span></em></td>
	</tr>

	<tr>
		<th>Password:</th>
		<td><input type="password"
			onfocus="if(this.value == 'Password'){
	this.value = '';
	}"
			onblur="password = this.value;" value='Password'
		/></td>
	</tr>

	<tr>
		<td></td>
		<td><input align="right" class="ui-corner-all ui-state-default"
			type="button"
			onclick="insertNewProfile(first_name, last_name, gender, date_of_birth, local_address, username, password, user_type_id, setProfileId);"
			value="Register"
		/></td>
	</tr>
</table>

<?php 
}

?>
